<template>
  <common-search :col-layout="{xxl: 6, xl:8, lg: 8, md: 12, sm: 24, xs: 24}" v-model="query" :formItems="formItems" @search="search" @reset="reset"></common-search>
  <a-button type="primary" @click="exports" :loading="exportLoading" v-modulePerm="['platformLogistics:export']">
    <template #icon>
      <ExportOutlined />
    </template>
    导出
  </a-button>
  <common-table
      :columns="columns"
      :dataSource="dataList"
      v-model:localPagination="page"
      @paginationChange="onPageChange"
      v-model:loading="loading"
      :scroll="{ x: 'max-content'}"
      :slots="['orderId','saleOrderCode']"
  >
    <template #orderId="{record}">
      <a @click="$router.push({path:'/orderStandardization/orderDetail',query:{id:record.orderId,platform:record.platform}})">{{record.orderId}}</a>
    </template>
    <template #saleOrderCode="{record}">
      <a @click="$router.push({path:'/orderStandardization/orderDetail',query:{id:record.saleOrderCode,platform:record.platform}})">{{record.saleOrderCode}}</a>
    </template>
  </common-table>
</template>
<script>
export default {
  name:'logistics-platformLogistics'
}
</script>
<script setup>
import { ref,onMounted } from "vue";
import CommonTable from "@/components/commonTable/index.vue";
import CommonSearch from "@/components/commonSearch/index.vue";
import {useSearchTable} from "@/hooks/table/useSearchTable";
import {getUserList} from "@/api/system/user.js";
import {getManyDictItems} from "@/api/system/dict.js";
import {getAccessoryPage} from "@/api/inventoryPools/accessoryPool.js";
import {message} from "ant-design-vue";
import {postFile} from "@utils/service/index.js";
import {getOrderPage} from "@/api/logistics/index.js";
const columns = [
  {
    "dictCode": "platform",
    "dataIndex": "platform",
    "title": "平台",
    "align": "center",
  },
  {

    "dataIndex": "orderId",
    "title": "平台订单",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dictCode": "site",
    "dataIndex": "site",
    "title": "站点",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "saleOrderCode",
    "title": "易仓订单",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "reloadFlag_dictText",
    "title": "重发标识",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "dateCreateSys",
    "title": "下单时间",
    "align": "center",
    "fieldType": "Date"
  },
  {
    "dataIndex": "statusName",
    "title": "易仓状态中文",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "deliveryStatus",
    "title": "尾程状态",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "warehouseCode",
    "title": "发货仓库",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "containerNo",
    "title": "柜号",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "etaDate",
    "title": "柜号到港",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "courierCode",
    "title": "承运商",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dictCode": "deliveryType",
    "dataIndex": "deliveryType",
    "title": "物流类型",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "shippingMethodNo",
    "title": "尾程跟踪号",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "dateWarehouseShipping",
    "title": "发货时间",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "transitTime",
    "title": "揽件时间",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "scheduledDeliveryDate",
    "title": "派送预约时间",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "deliveredTime",
    "title": "妥投时间",
    "align": "center",
    "fieldType": "Date"
  },
  {

    "dataIndex": "shippingRegion",
    "title": "收货州",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "shippingPostcode",
    "title": "收货邮编",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "shippingCountry",
    "title": "收货国家",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dictCode": "specialService",
    "dataIndex": "specialService_dictText",
    "title": "特殊服务",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "latestEvent",
    "title": "最后事件",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "latestEventTime",
    "title": "最后事件时间",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "estimatePrice",
    "title": "包裹价值",
    "align": "center",
    "fieldType": "String"
  },
  {

    "isTotal": "0",
    "dataIndex": "currencyCode",
    "groupTitle": "",
    "title": "币种",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "deliveryFee",
    "title": "尾程费用",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "feeCurrencyCode",
    "title": "尾程费用币种",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "isWarn_dictText",
    "title": "告警",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "warnMessage",
    "title": "告警信息",
    "align": "center",
    "fieldType": "String"
  },
  {

    "dataIndex": "userAccount",
    "title": "店铺账号",
    "align": "center",
    "fieldType": "String"
  },
  {
    "dataIndex": "isTransRegional",
    "title": "跨区派送",
    "align": "center",
    "fieldType": "String"
  }
]
const formItems = ref([
  {
    label:'平台',
    type:'select',
    field:'platform',
    options:[]
  },
  {
    label:"平台订单",
    type:'input',
    field: 'orderId',
  },
  {
    label:'站点',
    type:'select',
    field:'site',
    options:[]
  },
  {
    label:"易仓订单",
    type:'input',
    field: 'saleOrderCode',
  },
  {
    label:'重发标识',
    type:'select',
    field:'reloadFlag',
    options:[]
  },
  {
    label:"下单时间",
    type:'rangePicker',
    field: 'time1',
    showTime: false
  },
  {
    label:'尾程状态',
    type:'select',
    field:'deliveryStatus',
    options:[]
  },
  {
    label:"发货仓库",
    type:'input',
    field: 'warehouseCode',
  },
  {
    label:"柜号",
    type:'input',
    field: 'containerNo',
  },
  {
    label:"承运商",
    type:'input',
    field: 'courierCode',
  },
  {
    label:"物流类型",
    type:'select',
    field: 'deliveryType',
    options:[]
  },
  {
    label:"尾程跟踪号",
    type:'input',
    field: 'shippingMethodNo',
  },
  {
    label:"发货时间",
    type:'rangePicker',
    field: 'time2',
    showTime: false
  },
  {
    label:"揽件时间",
    type:'rangePicker',
    field: 'time3',
    showTime: false
  },
  {
    label:"派送预约时间",
    type:'rangePicker',
    field: 'time4',
    showTime: false
  },
  {
    label:"妥投时间",
    type:'rangePicker',
    field: 'time5',
    showTime: false
  },
  {
    label:"收货国家",
    type:'input',
    field: 'shippingCountry',
  },
  {
    label:"特殊服务",
    type:'select',
    field: 'specialService',
    options:[]
  },
  {
    label:"告警",
    type:'select',
    field: 'isWarn',
    options:[]
  },
  {
    label:"跨区派送",
    type:'select',
    field: 'isTransRegional',
    options:[]
  },
])
const selectedRowKeys = ref([])
const exportLoading = ref(false)
const { dataList, query, loading, page, search, reset, onPageChange } = useSearchTable({
  searchAPI: getOrderPage,
  queryFactory: () => ({
    columns:'createTime'
  }),
  beforeSearch: () => {
    //处理日期
    if(query.value.time1){
      query.value.dateCreateSysBegin = query.value.time1[0]
      query.value.dateCreateSysEnd = query.value.time1[1]
    }else{
      delete query.value.dateCreateSysBegin
      delete query.value.dateCreateSysEnd
    }
    if(query.value.time2){
      query.value.dateWarehouseShippingBegin = query.value.time2[0]
      query.value.dateWarehouseShippingEnd = query.value.time2[1]
    }else{
      delete query.value.dateWarehouseShippingBegin
      delete query.value.dateWarehouseShippingEnd
    }
    if(query.value.time3){
      query.value.transitTimeBegin = query.value.time3[0]
      query.value.transitTimeEnd = query.value.time3[1]
    }else{
      delete query.value.transitTimeBegin
      delete query.value.transitTimeEnd
    }
    if(query.value.time4){
      query.value.scheduledDeliveryDateBegin = query.value.time4[0]
      query.value.scheduledDeliveryDateEnd = query.value.time4[1]
    }else{
      delete query.value.scheduledDeliveryDateBegin
      delete query.value.scheduledDeliveryDateEnd
    }
    if(query.value.time5){
      query.value.deliveredTimeBegin = query.value.time5[0]
      query.value.deliveredTimeEnd = query.value.time5[1]
    }else{
      delete query.value.deliveredTimeBegin
      delete query.value.deliveredTimeEnd
    }
  },
});
/**
 * 初始化字典数据
 * @returns {Promise<void>}
 */
const init = async () => {
  try{
    const res = await getManyDictItems({
      dictCodeList:"boolean_cn,platforms,site,special_service,delivery_type,delivery_status"
    })
    formItems.value[0].options = res.result.platforms
    formItems.value[2].options = res.result.site
    formItems.value[4].options = res.result.boolean_cn
    formItems.value[6].options = res.result.delivery_status
    formItems.value[10].options = res.result.delivery_type
    formItems.value[17].options = res.result.special_service
    formItems.value[18].options = res.result.boolean_cn
    formItems.value[19].options = res.result.boolean_cn
  }catch (e){
    console.log(e)
  }
}
/**
 *  选择行变化事件
 * @param e {Array} 选择行的keys
 */
const onSelectChange = (e) => {
  selectedRowKeys.value = e
}
const exports = async () => {
  try{
    exportLoading.value = true
    const res = await postFile('/tms/sale/order/export','post',query.value,'全平台物流单.xlsx')
    message.success('导出成功')
  }catch (e) {
    message.error(e)
  }finally {
    exportLoading.value = false
  }
}
onMounted(()=>{
  init()
})
</script>
<style scoped>

</style>
